package com.qiangesoft.mybatisflex.config;

import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.tenant.TenantFactory;
import com.qiangesoft.mybatisflex.base.BaseEntity;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类
 */
@Configuration
public class MyBatisFlexConfiguration {

    public MyBatisFlexConfiguration() {
        FlexGlobalConfig config = FlexGlobalConfig.getDefaultConfig();
        config.registerSetListener(new MySetListener(), BaseEntity.class);
        config.registerInsertListener(new MyInsertListener(), BaseEntity.class);
        config.registerUpdateListener(new MyUpdateListener(), BaseEntity.class);
    }

    /**
     * 租户工厂
     */
    @Bean
    public TenantFactory tenantFactory() {
        return new MyTenantFactory();
    }

}